<template>
  <div class="roles">
    <!-- 面包屑导航 -->
    <el-breadcrumb separator="->" class="mb-15">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>
        <a href="javascript:;">权限管理</a>
      </el-breadcrumb-item>
      <el-breadcrumb-item>权限列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 权限表格 -->
    <el-table :data="rightsList" border style="width: 100%">
         <el-table-column
      type="index"
      width="50"
      label="索引"
      >
    </el-table-column>
      <el-table-column prop="authName" label="权限名称"></el-table-column>
      <el-table-column prop="path" label="路径"></el-table-column>
      <el-table-column prop="level" label="层级">
          <template slot-scope="scope">
        <el-tag
          :type="getType(scope.row.level)">
          {{scope.row.level|filterLevel}}
        </el-tag>
      </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
// 引入api
import { getRights } from '@/api'
export default {
  data () {
    return {
      rightsList: [],
      tag: ''
    }
  },
  created () {
    this.init()
  },
  filters: {
    filterLevel (data) {
      let str = ''
      switch (data) {
        case '0':
          str = '一级'
          break
        case '1':
          str = '二级'
          break

        default:
          str = '三级'
          break
      }
      return str
    }
  },
  methods: {
    //   初始化页面 发送请求 获取第一页的数据
    init () {
      getRights('list').then(res => {
        console.log(res)
        if (res.meta.status === 200) {
          this.rightsList = res.data
        }
      })
    },
    getType (data) {
      let str = ''
      switch (data) {
        case '0':
          str = ''
          break
        case '1':
          str = 'success'
          break

        default:
          str = 'danger'
          break
      }
      return str
    }
  }
}
</script>

<style lang="scss" scoped>
  .roles {
    .el-icon-arrow-right {
      margin-left: 5px;
    }
    .add-user {
      margin: 15px 0;
    }
  }
</style>
